/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Topka;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * @author Asko
 */
public class ClockTickApi extends JPanel {

    Graphics2D g2;

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        Graphics2D newg = (Graphics2D) g;
        MouseMove mm = new MouseMove();
        this.addMouseMotionListener(mm);
        func(newg, (int) mm.getX(), (int) mm.getY(), 20);
    }

    public Graphics2D getG2() {
        return g2;
    }

    public void func(Graphics2D g, int x, int y, int r) {

        double startTime = System.currentTimeMillis();
        System.out.println("Loop started");
        while (System.currentTimeMillis() < startTime + 5000) {
            g.fillOval(x + 1, y + 1, r, r);
        }
        System.out.println("Loop ended");
    }

    public void setG2(Graphics2D g2) {
        this.g2 = g2;
    }
    
    /**
     * Let's go outside,shall we?
     * Shall we dance?
     * Let's go in that building.
     */
    @Override
    public void repaint() {
        super.repaint();
    }

    public static void main(String[] args) {
        JFrame f = new JFrame("Going");
        ClockTickApi capi = new ClockTickApi();
        f.add(capi);
        f.pack();
        f.setSize(200, 200);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    }
}
